package cn.com.beans;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.management.relation.Role;

/**
 * 账号信息表
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PAccount {
    private Integer id;

    private String account;

    private String password;

    private String root;
    /**
     * 账号拥有的角色信息
     */
    private List<PRole> roles;

    public List<PResource> getResource(){
        List<PResource> resources = new ArrayList<>();
        if(roles!=null){
            for(PRole role:roles){
                resources.addAll(role.getResources());
            }
        }
        //将资源进行去重返回
        return resources.stream().distinct().collect(Collectors.toList());
    }

    public String getRoot() {
        return root;
    }

    public void setRoot(String root) {
        this.root = root;
    }

    public List<PRole> getRoles() {
        return roles;
    }

    public void setRoles(List<PRole> roles) {
        this.roles = roles;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}